<?php
class Paging_model extends CI_Model {
 
	private $s_key_one = FALSE;
	private $s_key_two = FALSE;
	private $s_key_three = FALSE;
	private static $search_terms = array('s_key_one', 's_key_two', 's_key_three');
 
/**
 *
 * Here goes your function description
 *
*/	
	function __construct(){
 
		parent::__construct();
		$this->search_terms = self::$search_terms;
		$this->_check_search_session();
 
	}
 
/**
 *
 * Here goes your function description
 *
*/	
	function _check_search_session(){
 
		foreach($this->search_terms as $key => $val){
 
			$chk = $this->session->userdata($val);
			if($chk !== FALSE){
 
				if(empty($chk)){
					$this->$val = FALSE;
				}
				else {
					$this->$val = $chk;
				}
				unset($chk);
 
			}
		}
	}
 
/**
 *
 * Here goes your function description
 *
*/	
	function _filter(){
 
		if($this->s_key_one !== FALSE){
			$this->db->where("applications.key_one = '" . $this->s_key_one . "' ");
		}
 
		if($this->s_key_two !== FALSE){
 
			$this->db->where(" applications.key_two LIKE('%" . $this->s_key_two . "%') ");
 
		}
 
		if($this->s_key_three !== FALSE){
 
			$this->db->where(" DATE(applications.key_three) >= DATE(FROM_UNIXTIME(" . strtotime($this->s_key_three . ' 00:00:00') . ")) ");
 
		}
 
	}
 
/**
 *
 * Here goes your function description
 *
*/	
	function count_all(){
 
		$this->db->select("applications.id");
 
		$this->_filter();
 
		$query = $this->db->get("applications");
 
		return $query->num_rows();
 
	}
 
/**
 *
 * Here goes your function description
 *
*/
	function get_all($limit, $offset){
 
		$this->db->select("applications.*");
 
		$this->_filter();
 
		$this->db->order_by("applications.id", "DESC"); 
		$this->db->limit($limit, $offset);
		$query = $this->db->get("applications");
 
		if($query->num_rows() > 0){
 
 
//			return $query->result();
			return $query->result_array();
 
		}
		return FALSE;
 
	}
 
}
 
/* End of file application_model.php */
/* Location: ./system/application/models/application_model.php */